package com.sprocomm.agingtest.reboot;

import com.sprocomm.agingtest.R;
import com.sprocomm.agingtest.Tools;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.widget.Toast;

public class MyBootReceiver extends BroadcastReceiver {
    private String TAG = "MyBootReceiver";

    public MyBootReceiver() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        Tools.logE("MyBootReceiver");
        Toast.makeText(context, "MyBootReceiver", Toast.LENGTH_LONG).show();
        NotificationManager notificationManager =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new NotificationCompat.Builder(context)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentText("boot")
                .setContentTitle("bootComplete")
                .build();
        notificationManager.notify(1, notification);
        boolean isTest;
        SharedPreferences sharedPreferences = context.getSharedPreferences("reboot", Context.MODE_PRIVATE);
        isTest = sharedPreferences.getBoolean("isTest", false);
        if (isTest) {
            Intent intent1 = new Intent(context, RebootTest.class);
            intent.putExtra("isManual", false);
            intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent1);
        }

    }
}
